package ICM.client;

import java.io.IOException;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import ocsf.client.ObservableClient;

public class Client extends ObservableClient{
	
	static public String Login;
	
	/**
	 * Constructor
	 * @param host Server host
	 * @param port Server port
	 */
	public Client(String host, int port) {
		super(host, port);

	}

	/**
	 * @param args
	 * @throws SQLException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws SQLException, IOException {
		String host[] = new String[1];
		host[0] = "localhost";
		int[] port = new int[1];
		port[0] = 5555;
		// Create new object: Client, ClientUI	
		if (!SettingsUI.LoadSettings(host, port))
		{
			SettingsUI tmp = new SettingsUI(null);
			tmp.SaveSettings(host[0], port[0]);
		}
		Client c = new Client(host[0],port[0]);
		ClientUI ui = new ClientUI(c);
		
		// Add ClientUI to Client for massage handling 
		c.addObserver(ui);
		
		// Show UI
		ui.SetContent(ClientUI.LOGIN_SCREEN);
		ui.setVisible(true);
		// Connect to server
		try {
			c.openConnection();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ClientUI.ShowMessageBox("Error", "Can't connect to the server.", JOptionPane.ERROR_MESSAGE);
		}
	}
}
